Title: SQL BT (By-BKK) / 16 Create
Tags: Obsidian_to_Anki

Q: What SQL statement creates a new table?
A: CREATE TABLE

Q: What does a table schema define in SQL?
A: The columns, data types, constraints, and default values for a table

Q: True/False: You can suppress errors when creating an existing table in SQL.
A: True, by using IF NOT EXISTS

Q: What clause prevents an error if the table already exists in SQL?
A: IF NOT EXISTS

Q: Name three common SQL data types used in tables.
A: INTEGER, TEXT, DATE

Q: What constraint ensures column values are unique and identifies each row?
A: PRIMARY KEY

Q: True/False: AUTOINCREMENT automatically increases integer values on insert.
A: True

Q: What does the UNIQUE constraint enforce in a table?
A: Values in the column must not be duplicated

Q: What constraint ensures a value cannot be NULL in a column?
A: NOT NULL

Q: How does CHECK work as a table constraint?
A: It validates inserted values using custom expressions

Q: What is a FOREIGN KEY in SQL?
A: A constraint ensuring a column’s value matches a value in another table’s column

Q: Give an example of a CREATE TABLE statement for a movies schema.
A: CREATE TABLE movies (id INTEGER PRIMARY KEY, title TEXT, director TEXT, year INTEGER, length_minutes INTEGER);

Q: How can text types like CHARACTER and VARCHAR differ?
A: They specify the maximum characters stored for efficiency

Q: What is a BLOB data type in SQL tables?
A: A column for storing binary data

Q: How do you create a table with three columns, Name, Version, and Download_count?
A: CREATE TABLE Database (Name TEXT, Version FLOAT, Download_count INTEGER);

Q: What SQL command do you use to define a new table?
A: CREATE TABLE statement

Q: What does table schema enforce about column data?
A: Columns in a table must match the defined schema

Q: What does FOREIGN KEY do in SQL?
A: The FOREIGN KEY constraint links data to another table

Q: How do you prevent SQL from throwing an error if a table already exists?
A: IF NOT EXISTS in CREATE TABLE avoids errors if the table is present

Q: What constraint can you use to require values meet certain rules?
A: CHECK constraints let you set required conditions for values

Q: Which SQL column type is used for images or files?
A: BLOB types store binary data